package com.lechuang.file.style;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;

/**
 * <p>
 *
 * </p>
 * @author liaoningbo
 * @since 2023/6/7
*/
public class DataCellStyle extends AbstractVerticalCellStyleStrategy {

    public DataCellStyle(){

    }

    @Override
    protected WriteCellStyle headCellStyle(Head head) {
        WriteCellStyle cellStyle=new WriteCellStyle();
        WriteFont font=new WriteFont();
        //设置字体颜色
        font.setColor(IndexedColors.BLACK.getIndex());
        //设置字体
        font.setFontName("SansSerif");
        //设置字体大小
        font.setFontHeightInPoints((short) 12);
        //设置文字加粗
        font.setBold(true);
        cellStyle.setWriteFont(font);

        //设置边框颜色
        cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
        //设置边框样式
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setBorderTop(BorderStyle.THIN);
        //设置居中
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        //设置单元格的背景颜色
        cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        //设置自动单元格自动大小
//        cellStyle.setShrinkToFit(true);
        return cellStyle;
    }

    @Override
    protected WriteCellStyle contentCellStyle(Head head) {
        WriteCellStyle cellStyle=new WriteCellStyle();
        WriteFont font=new WriteFont();
        //设置字体颜色
        font.setColor(IndexedColors.BLACK.getIndex());
        //设置字体
        font.setFontName("SansSerif");
        //设置字体大小
        font.setFontHeightInPoints((short) 11);
        cellStyle.setWriteFont(font);

        //设置边框颜色
        cellStyle.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
        cellStyle.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
        cellStyle.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
        cellStyle.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
        //设置边框样式
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setBorderTop(BorderStyle.THIN);
        //设置居中
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        //设置单元格的背景颜色
        cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        //设置自动单元格自动大小
//        cellStyle.setShrinkToFit(true);
        return cellStyle;
    }
}
